package com.example.administrator.pandanotes;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by 于博 on 2018-07-14.
 * 笔记列表适配器
 */

public class NoteAdapter extends ArrayAdapter {
    private int resourceId;

    public NoteAdapter(Context context, int resource, List NoteList) {
        super(context, resource, NoteList);
        resourceId = resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Note note = (Note) getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);//实例化一个view对象
        TextView tVBookName = (TextView) view.findViewById(R.id.tVBookName);
        TextView tVNoteDate = (TextView) view.findViewById(R.id.tVNoteDate);
        TextView tVNoteCon = (TextView) view.findViewById(R.id.tVNoteCon);
        TextView tvBookPage = (TextView) view.findViewById(R.id.tVBookPage);
        tVBookName.setText(note.getBook_name());
        tVNoteDate.setText(note.getStr_date());
        tvBookPage.setText("    "+note.getNote_page()+"   ");
        String str = note.getNote_content();
        if(str.length()>4)str=str.substring(0,4)+"...";//显示4个
        tVNoteCon.setText(str);
        return view;
    }
}
